package zstu.edu.cn.notepad;

import android.support.annotation.NonNull;
import android.util.Log;


import java.io.IOException;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class Get {
    private static Request request;
    public static void requestGet(String  Url,final TtitCallback callback){
        OkHttpClient okHttpClient = new OkHttpClient();
        request = new Request.Builder()
                .url("http://"+Common.IP+":8080/"+Url)
                .get()
                .build();
        Call call = okHttpClient.newCall(request);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(@NonNull Call call, @NonNull IOException e) {
                Log.d("TAG", "onFailure: ======> 请求失败");
            }

            @Override
            public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
                try {
                    callback.onSuccess(response.body().string());

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }
}